/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package triploa;
import java.io.IOException;
import org.kxml2.io.KXmlParser;
import org.xmlpull.v1.XmlPullParserException;
/**
 *
 * @author Edoardo
 */
public class Notification {
   private int id,senderId,travelId,userId,template;
   private Notification()
{
    userId=0;
    senderId=0;
    travelId=0;
    id=0;
    template=0;
}
    public static final String NOTIFICATION_TAG="a:Notification";
public static final String ID_TAG="a:EventId";
public static final String FIELDS_TAG="a:Fields";
public static final String SENDER_TAG="a:SenderID";
public static final String TEMPLATE_TAG="a:TemplateType";
public static final String TRAVEL_TAG="a:TripId";
public static final String USER_TAG="a:UserId";
/**
 * call for getting a new instance of this class from xml
 * @param p Parser
 * @return a new instance of FeedBack
 * @throws java.io.IOException
 * @throws org.xmlpull.v1.XmlPullParserException
 */
    public static Notification create(KXmlParser p)throws IOException, XmlPullParserException
{
    Notification l=new Notification();
    l.update(p);
    if( l.id==0&&l.senderId==0&&l.travelId==0&&l.template==0&&l.userId==0) return null;
    return l;
}
    /**
 * Update this object class from xml parser
 * @param p Parser
 * @throws java.io.IOException
 * @throws org.xmlpull.v1.XmlPullParserException
 */
public void update(KXmlParser p) throws IOException, XmlPullParserException
{
       boolean exit = false,rec=false, travel = false;
        int token = -1;
        String n="",lasttag=n;
        while (!exit) {
            token = p.next();
            switch (token) {
                case KXmlParser.START_DOCUMENT:
                    break;
                case KXmlParser.END_DOCUMENT:
                    exit = true;  //exit form while
                    break;
                case KXmlParser.START_TAG:
                    System.out.println(p.getName());
                    if (p.getName().equals(NOTIFICATION_TAG)) {
                        travel = true;
                    }
                    
                    if(travel) lasttag=p.getName();
                    break;
                case KXmlParser.END_TAG:
                    if (travel) {
                        if (p.getName().equals(NOTIFICATION_TAG)) {
                            travel = false;
                            exit = true;
                            break;
                        }
                    }
                    
                    lasttag=n;
                    break;
                case KXmlParser.TEXT:
                    
                    if (lasttag.equals(ID_TAG)) {
                        id = Integer.parseInt(p.getText());
                    }
                    
                    if (lasttag.equals(SENDER_TAG)) {
                        senderId =  Integer.parseInt(p.getText());
                    }
                    //if (lasttag.equals(RECEIVER_TAG)) {
                     //   receivers = p.getText();
                    //}
                    if (lasttag.equals(TEMPLATE_TAG)) {
                        template =  Integer.parseInt(p.getText());
                    }
                    if (lasttag.equals(USER_TAG)) {
                        userId =  Integer.parseInt(p.getText());
                    }
                    if (lasttag.equals(TRAVEL_TAG)) {
                        travelId =  Integer.parseInt(p.getText());
                    }
                    
                    break;
            }
        }
}

}